package com.test.demo.work;

import com.test.demo.work.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FormXml {


    public static void main(String[] args) {
        String para="<GridColumn Key=\"PersonnelCategory\" Caption=\"人员类别\" Width=\"80px\"/>\n" +
                "                                <GridColumn Key=\"NameOS\" Caption=\"姓名\" Width=\"80px\"/>\n" +
                "                                <GridColumn Key=\"Job\" Caption=\"职务\" Width=\"80px\"/>\n" +
                "                                <GridColumn Key=\"Sex\" Caption=\"性别\" Width=\"80px\"/>\n" +
                "                                <GridColumn Key=\"MailBox\" Caption=\"电子邮箱\" Width=\"80px\"/>\n" +
                "                                <GridColumn Key=\"Telephone\" Caption=\"电话号码\" Width=\"80px\"/>\n" +
                "                                <GridColumn Key=\"Cellphone\" Caption=\"手机号码\" Width=\"80px\"/>";
        getJaveField(para);
        System.out.println(Pattern.matches("^[\\u4e00-\\u9fa5_a-zA-Z0-9]+$","1132手机号码"));
        System.out.println(Pattern.matches("\\w*","1132ff"));
    }

    public static void getJaveField(String para){
        List<String> valueByKey = getValueByKey(para,"Key");
        List<String> caption = getValueByKey(para,"Caption");
        for (int i = 0; i < valueByKey.size(); i++) {
            System.out.println("/**");
            System.out.println("*"+caption.get(i));
            System.out.println("*/");
            System.out.println("private String "+ StringUtil.toLowerCaseFirstOne(valueByKey.get(i)) +";");
        }
    }

    /**
     * 查找所有key="value"  的value
     * @param para
     * @return
     */
    public static List<String> getValueByKey(String para,String start){
        List<String> matchRegexList = new ArrayList<>();
        String startregex=start+"=\"";
        //String regex="\\w*";
        String regex="^[\\u4e00-\\u9fa5_a-zA-Z0-9]+$*";
        String endregex="\"";
        String myregex=startregex+regex+endregex;
        Pattern pattern = Pattern.compile(myregex);
        Matcher matcher = pattern.matcher(para);
        while(matcher.find()){
            String group = matcher.group();
            group = group.replaceAll(startregex, "").replaceAll(endregex,"");
            matchRegexList.add(group);
        }
        return matchRegexList;
    }

//    public static List<String> getValueByKey(String para,String startregex){
//
//    }

}
